package com.j256.ormlite.misc;

import com.j256.ormlite.db.DatabaseType;
import com.j256.ormlite.logger.Logger;
import com.j256.ormlite.logger.LoggerFactory;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.support.DatabaseConnection;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;

public class TransactionManager
{
  private static final String SAVE_POINT_PREFIX = "ORMLITE";
  private static final Logger logger = LoggerFactory.getLogger(TransactionManager.class);
  private static AtomicInteger savePointCounter = new AtomicInteger();
  private ConnectionSource connectionSource;

  public TransactionManager()
  {
  }

  public TransactionManager(ConnectionSource paramConnectionSource)
  {
    this.connectionSource = paramConnectionSource;
    initialize();
  }

  public static <T> T callInTransaction(ConnectionSource paramConnectionSource, Callable<T> paramCallable)
    throws SQLException
  {
    DatabaseConnection localDatabaseConnection = paramConnectionSource.getReadWriteConnection();
    try
    {
      Object localObject2 = callInTransaction(localDatabaseConnection, paramConnectionSource.saveSpecialConnection(localDatabaseConnection), paramConnectionSource.getDatabaseType(), paramCallable);
      return localObject2;
    }
    finally
    {
      paramConnectionSource.clearSpecialConnection(localDatabaseConnection);
      paramConnectionSource.releaseConnection(localDatabaseConnection);
    }
  }

  public static <T> T callInTransaction(DatabaseConnection paramDatabaseConnection, DatabaseType paramDatabaseType, Callable<T> paramCallable)
    throws SQLException
  {
    return callInTransaction(paramDatabaseConnection, false, paramDatabaseType, paramCallable);
  }

  // ERROR //
  public static <T> T callInTransaction(DatabaseConnection paramDatabaseConnection, boolean paramBoolean, DatabaseType paramDatabaseType, Callable<T> paramCallable)
    throws SQLException
  {
    // Byte code:
    //   0: iconst_0
    //   1: istore 4
    //   3: iload_1
    //   4: ifne +25 -> 29
    //   7: aload_2
    //   8: invokeinterface 75 1 0
    //   13: istore 14
    //   15: iconst_0
    //   16: istore 4
    //   18: iconst_0
    //   19: istore 8
    //   21: aconst_null
    //   22: astore 7
    //   24: iload 14
    //   26: ifeq +95 -> 121
    //   29: aload_0
    //   30: invokeinterface 80 1 0
    //   35: istore 6
    //   37: iconst_0
    //   38: istore 4
    //   40: iload 6
    //   42: ifeq +31 -> 73
    //   45: aload_0
    //   46: invokeinterface 83 1 0
    //   51: istore 4
    //   53: iload 4
    //   55: ifeq +18 -> 73
    //   58: aload_0
    //   59: iconst_0
    //   60: invokeinterface 87 2 0
    //   65: getstatic 24	com/j256/ormlite/misc/TransactionManager:logger	Lcom/j256/ormlite/logger/Logger;
    //   68: ldc 89
    //   70: invokevirtual 95	com/j256/ormlite/logger/Logger:debug	(Ljava/lang/String;)V
    //   73: aload_0
    //   74: new 97	java/lang/StringBuilder
    //   77: dup
    //   78: invokespecial 98	java/lang/StringBuilder:<init>	()V
    //   81: ldc 8
    //   83: invokevirtual 102	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   86: getstatic 31	com/j256/ormlite/misc/TransactionManager:savePointCounter	Ljava/util/concurrent/atomic/AtomicInteger;
    //   89: invokevirtual 106	java/util/concurrent/atomic/AtomicInteger:incrementAndGet	()I
    //   92: invokevirtual 109	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
    //   95: invokevirtual 113	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   98: invokeinterface 117 2 0
    //   103: astore 7
    //   105: aload 7
    //   107: ifnonnull +56 -> 163
    //   110: getstatic 24	com/j256/ormlite/misc/TransactionManager:logger	Lcom/j256/ormlite/logger/Logger;
    //   113: ldc 119
    //   115: invokevirtual 95	com/j256/ormlite/logger/Logger:debug	(Ljava/lang/String;)V
    //   118: iconst_1
    //   119: istore 8
    //   121: aload_3
    //   122: invokeinterface 125 1 0
    //   127: astore 13
    //   129: iload 8
    //   131: ifeq +9 -> 140
    //   134: aload_0
    //   135: aload 7
    //   137: invokestatic 129	com/j256/ormlite/misc/TransactionManager:commit	(Lcom/j256/ormlite/support/DatabaseConnection;Ljava/sql/Savepoint;)V
    //   140: iload 4
    //   142: ifeq +18 -> 160
    //   145: aload_0
    //   146: iconst_1
    //   147: invokeinterface 87 2 0
    //   152: getstatic 24	com/j256/ormlite/misc/TransactionManager:logger	Lcom/j256/ormlite/logger/Logger;
    //   155: ldc 131
    //   157: invokevirtual 95	com/j256/ormlite/logger/Logger:debug	(Ljava/lang/String;)V
    //   160: aload 13
    //   162: areturn
    //   163: getstatic 24	com/j256/ormlite/misc/TransactionManager:logger	Lcom/j256/ormlite/logger/Logger;
    //   166: ldc 133
    //   168: aload 7
    //   170: invokeinterface 138 1 0
    //   175: invokevirtual 141	com/j256/ormlite/logger/Logger:debug	(Ljava/lang/String;Ljava/lang/Object;)V
    //   178: goto -60 -> 118
    //   181: astore 5
    //   183: iload 4
    //   185: ifeq +18 -> 203
    //   188: aload_0
    //   189: iconst_1
    //   190: invokeinterface 87 2 0
    //   195: getstatic 24	com/j256/ormlite/misc/TransactionManager:logger	Lcom/j256/ormlite/logger/Logger;
    //   198: ldc 131
    //   200: invokevirtual 95	com/j256/ormlite/logger/Logger:debug	(Ljava/lang/String;)V
    //   203: aload 5
    //   205: athrow
    //   206: astore 11
    //   208: iload 8
    //   210: ifeq +9 -> 219
    //   213: aload_0
    //   214: aload 7
    //   216: invokestatic 144	com/j256/ormlite/misc/TransactionManager:rollBack	(Lcom/j256/ormlite/support/DatabaseConnection;Ljava/sql/Savepoint;)V
    //   219: aload 11
    //   221: athrow
    //   222: astore 12
    //   224: getstatic 24	com/j256/ormlite/misc/TransactionManager:logger	Lcom/j256/ormlite/logger/Logger;
    //   227: aload 11
    //   229: ldc 146
    //   231: invokevirtual 150	com/j256/ormlite/logger/Logger:error	(Ljava/lang/Throwable;Ljava/lang/String;)V
    //   234: goto -15 -> 219
    //   237: astore 9
    //   239: iload 8
    //   241: ifeq +9 -> 250
    //   244: aload_0
    //   245: aload 7
    //   247: invokestatic 144	com/j256/ormlite/misc/TransactionManager:rollBack	(Lcom/j256/ormlite/support/DatabaseConnection;Ljava/sql/Savepoint;)V
    //   250: ldc 152
    //   252: aload 9
    //   254: invokestatic 158	com/j256/ormlite/misc/SqlExceptionUtil:create	(Ljava/lang/String;Ljava/lang/Throwable;)Ljava/sql/SQLException;
    //   257: athrow
    //   258: astore 10
    //   260: getstatic 24	com/j256/ormlite/misc/TransactionManager:logger	Lcom/j256/ormlite/logger/Logger;
    //   263: aload 9
    //   265: ldc 146
    //   267: invokevirtual 150	com/j256/ormlite/logger/Logger:error	(Ljava/lang/Throwable;Ljava/lang/String;)V
    //   270: goto -20 -> 250
    //
    // Exception table:
    //   from	to	target	type
    //   7	15	181	finally
    //   29	37	181	finally
    //   45	53	181	finally
    //   58	73	181	finally
    //   73	105	181	finally
    //   110	118	181	finally
    //   121	129	181	finally
    //   134	140	181	finally
    //   163	178	181	finally
    //   213	219	181	finally
    //   219	222	181	finally
    //   224	234	181	finally
    //   244	250	181	finally
    //   250	258	181	finally
    //   260	270	181	finally
    //   121	129	206	java/sql/SQLException
    //   134	140	206	java/sql/SQLException
    //   213	219	222	java/sql/SQLException
    //   121	129	237	java/lang/Exception
    //   134	140	237	java/lang/Exception
    //   244	250	258	java/sql/SQLException
  }

  private static void commit(DatabaseConnection paramDatabaseConnection, Savepoint paramSavepoint)
    throws SQLException
  {
    if (paramSavepoint == null);
    for (String str = null; ; str = paramSavepoint.getSavepointName())
    {
      paramDatabaseConnection.commit(paramSavepoint);
      if (str != null)
        break;
      logger.debug("committed savePoint transaction");
      return;
    }
    logger.debug("committed savePoint transaction {}", str);
  }

  private static void rollBack(DatabaseConnection paramDatabaseConnection, Savepoint paramSavepoint)
    throws SQLException
  {
    if (paramSavepoint == null);
    for (String str = null; ; str = paramSavepoint.getSavepointName())
    {
      paramDatabaseConnection.rollback(paramSavepoint);
      if (str != null)
        break;
      logger.debug("rolled back savePoint transaction");
      return;
    }
    logger.debug("rolled back savePoint transaction {}", str);
  }

  public <T> T callInTransaction(Callable<T> paramCallable)
    throws SQLException
  {
    return callInTransaction(this.connectionSource, paramCallable);
  }

  public void initialize()
  {
    if (this.connectionSource == null)
      throw new IllegalStateException("dataSource was not set on " + getClass().getSimpleName());
  }

  public void setConnectionSource(ConnectionSource paramConnectionSource)
  {
    this.connectionSource = paramConnectionSource;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.j256.ormlite.misc.TransactionManager
 * JD-Core Version:    0.6.2
 */